<?php

namespace App\Admin\Exports;

use App\Model\Withdraw;
use Encore\Admin\Grid\Exporters\ExcelExporter;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;

class WithdrawExport extends ExcelExporter implements WithMapping, WithHeadings, ShouldAutoSize
{
    //这里是导出来的文件的名字和格式
    protected $fileName = '结算列表.xlsx';
    //这里是excel的标题
    public function headings(): array
    {
        return [
            '女用户ID',
            '女用户昵称',
            '商家单号ID',
            '微信OpenId',
            '收款用户姓名',
            '收款用户身份证',
            '提现人民币（元）',
            '备注',
            '支付宝账户',
            '银行卡',
        ];
    }

    public function map($data): array
    {
        $date = date('Ymd');
        return [
            $data->userProfile->user_profile_id,
            $data->userProfile->nick_name,
            $data->id,
            $data->personalProfile ? $data->personalProfile->wechat_openid : '',
            '',
            '',
            (string)$data->withdraw_rmb,
            date('Y-m-d') . '结算',
            $data->personalProfile->alipay_account,
            $data->personalProfile->bank_card,
        ];
    }
}
